﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication4
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string name = TextBox1.Text;
            string pwd = TextBox2.Text;
            string email = TextBox3.Text;
            string into = TextBox4.Text;
            string constr = "Data Source=LAPTOP-D4R08UGL;Initial Catalog=Student_db;Integrate Security=ture";
            SqlConnection con = new SqlConnection(constr);
            con.Open();
            string sql = "insert into StudentInfo (stu_name,password,email,into) values (@name,@pwd,@email,@into)";
            SqlParameter[] pars =
                {
                new SqlParameter("@name",name),
                new SqlParameter("@pwd",pwd),
                new SqlParameter("@email",email),
                new SqlParameter("@into",into)

            };
            SqlCommand cmd = new SqlCommand(sql, con);
            cmd.Parameters.AddRange(pars);
            int result = cmd.ExecuteNonQuery();
            if (result>0)
            {
                Literal1.Text = "注册成功 <a href ='WebForm1.aspx'>去登录</a>";
               
            }
            else
            {
                Literal1.Text = "注册失败！！";
            }
        }
    }
}